Opens a data channel.
データチャネルを開きます。
Open FileName As String [For Mode] [Access IOMode] [Protected] As [#]FileNumber As Integer [Len = DatasetLength]
Open FileName As String [For Mode] [Access IOMode] [Protected] As [#]FileNumber As Integer [Len = DatasetLength]
FileName: Name and path of the file that you wan to open. If you try to read a file that does not exist (Access = Read), an error message appears. If you try to write to a file that does not exist (Access = Write), a new file is created.
ファイル名:開こうとするファイルの名前とパス。存在しないファイルを読み取ろうとすると (Access = Read)、エラーメッセージが表示されます。存在しないファイルを書き込もうとすると (Access = Write)、新しいファイルが作成されます。
Mode: Keyword that specifies the file mode. Valid values: Append (append to sequential file), Binary (data can be accessed by bytes using Get and Put), Input (opens data channel for reading), Output (opens data channel for writing), and Random (edits relative files).
モード: ファイルモードを指定するキーワード。有効な値:Append (順編成ファイルに追加する)、Binary (データは、Get および Put を使用してバイトによってアクセスできる)、Input (読み取り用のデータチャネルを開く)、Output (書き込み用のデータチャネルを開く)、および Random (関連ファイルを編集する)。
IOMode: Keyword that defines the access type. Valid values: Read (read-only), Write (write-only), Read Write (both).
IOMode: アクセスの種類を定義するキーワードです。有効な値には、Read (読み取り専用)、Write (書き込み専用)、Read Write (読み取りと書き込み) があります。
Protected: Keyword that defines the security status of a file after opening. Valid values: Shared (file may be opened by other applications), Lock Read (file is protected against reading), Lock Write (file is protected against writing), Lock Read Write (denies file access).
Protected:オープン後のファイルのセキュリティステータスを指定するキーワード。これには下記の値を指定できます。Shared (ファイルを他のアプリケーションでも開けるようにする)、Lock Read (ファイルを読み取り保護する)、Lock Write (ファイルを書き込み保護する)、Lock Read Write (ファイルアクセスを禁止する)。
FileNumber: Any integer expression from 0 to 511 to indicate the number of a free data channel. You can then pass commands through the data channel to access the file. The file number must be determined by the FreeFile function immediately before the Open statement.
FileNumber:使用可能なデータチャネル番号を示す 0 から 511 までの整数表式。オープン後のファイルに対しては、データチャネルを通じてアクセスコマンドを渡せます。ファイル番号は、Open ステートメントの直前で FreeFile 関数を実行して取得する必要があります。
DatasetLength: For random access files, set the length of the records.
DatasetLength: ランダムアクセスファイル用にレコード長を設定します。
![]() | You can only modify the contents of a file that was opened with the Open statement. If you try to open a file that is already open, an error message appears.
内容を変更できるファイルは、Open ステートメントでオープンしたファイルだけです。オープン済みのファイルを再度オープンしようとすると、エラーメッセージが表示されます。 |
Sub ExampleWorkWithAFile
Sub ExampleWorkWithAFile
Dim iNumber As Integer
Dim iNumber As Integer
Dim sLine As String
Dim sLine As String
Dim aFile As String
Dim aFile As String
Dim sMsg as String
Dim sMsg as String
aFile = "c:\data.txt"
aFile = "c:\data.txt"
iNumber = Freefile
iNumber = Freefile
Open aFile For Output As #iNumber
Open aFile For Output As #iNumber
Print #iNumber, "This is a line of text"
Print #iNumber, "This is a line of text"
Print #iNumber, "This is another line of text"
Print #iNumber, "This is another line of text"
Close #iNumber
Close #iNumber
iNumber = Freefile
iNumber = Freefile
Open aFile For Input As iNumber
Open aFile For Input As iNumber
While not eof(iNumber)
While not eof(iNumber)
Line Input #iNumber, sLine
Line Input #iNumber, sLine
If sLine <>"" then
If sLine <>"" then
sMsg = sMsg & sLine & chr(13)
sMsg = sMsg & sLine & chr(13)
end if
end if
wend
Wend
Close #iNumber
Close #iNumber
Msgbox sMsg
Msgbox sMsg
End Sub
End Sub